<?php
include_once $_SERVER['DOCUMENT_ROOT']."/math-videos/configure.inc.php";
$asset_id = isset($_GET['id']) ? trim($_GET['id']):'';
$remote_url_flag = isset($_GET['rm']) ? trim($_GET['rm']):'N';
if($asset_id !='')
{
	$sqltext="INSERT INTO view_result(asset_id,click_date) values( ?, ?)";
	$params = array();
	array_push($params,sql_escape($asset_id));
	array_push($params,date("Y-m-d H:i:s"));
	db_change_query($conn,$sqltext,$params);
	
	$sqltext="select  id,	abstract_url, remote_url
							from asset
							where id=?";
	$params = array();
	array_push($params,sql_escape($asset_id));
	$result = db_select_query($conn,$sqltext,$params);
	$row = db_fetch_object($result);
	if(isset($row	))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			$$key = $value;
		}
		if(strtoupper($remote_url_flag) =='Y')
		{
			header( 'Location: '.$remote_url);
		}
		else
		{
			header( 'Location: '.$abstract_url);
		}
	}
	else
	{
		header("Location: " .$_SERVER['HTTP_REFERER']);
	}
		
}
else
{
	header("Location: " .$_SERVER['HTTP_REFERER']);
}

?>